package com.sky.mapper;

import com.sky.Entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.Map;

@Mapper
public interface OrderMapper {

    @Insert("insert into orders(number, status, user_id, address_book_id, order_time," +
            " checkout_time, pay_method, pay_status, amount, remark, phone, " +
            "address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, " +
            "estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status) values (" +
            "#{number},#{status},#{userId},#{addressBookId},#{orderTime}," +
            "#{checkoutTime},#{payMethod},#{payStatus},#{amount},#{remark},#{phone}," +
            "#{address},#{userName},#{consignee},#{cancelReason},#{rejectionReason},#{cancelTime}," +
            "#{estimatedDeliveryTime},#{deliveryStatus},#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Orders orders);

    @Update("update orders set status=#{cancelled},cancel_reason=#{cancelReason} where status=#{pendingPayment} and order_time<#{time}")
    void updatePayTimeOut(LocalDateTime time, Integer pendingPayment, Integer cancelled, String cancelReason);

    Double queryTurnoverByMap(Map map);

    Integer queryOrderCountByMap(Map map);
}
